import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2024-09-05
 * Time:16:27
 */
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();//面包机个数
        //制作a面包的时间
        int[] at = new int[n];
        int[] bt = new int[n];
        //记录a\b最短时间
        int ai = 0;
        int bi = 0;
        for(int i = 0;i<n;i++){
            at[i] = sc.nextInt();
            if(i != 0 && at[i] < at[ai]) {
                ai = i;
            }
        }
        for(int i = 0;i<n;i++){
            bt[i] = sc.nextInt();
            if(i != 0 && bt[i] < bt[bi]){
                bi = i;
            }
        }
        if(ai != bi){
            System.out.println(Math.max(at[ai],bt[bi]));
            return;
        }
        //ai == bi :
        int mina = at[ai];
        int minb = bt[bi];
        //寻找bt中最小的
        //找他
        int time = mina + minb;
        //找a小的
        Arrays.sort(at);
        int time1 = Math.max(at[1] , minb);
        //b小
        Arrays.sort(bt);
        int time2 = Math.max(mina,bt[1]);
        time = time<time1?time : time1;
        time = time < time2?time:time2;
        System.out.println(time);



    }
}
